/*
 * @Author: your name
 * @Date: 2020-05-05 16:44:04
 * @LastEditTime: 2020-05-19 19:58:31
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \v-nw-h5\src\store\getters\index.js
 */ 
import Vue from 'vue'
import Cookie from '../../../static/js/cookie'

export default {
    currentUserFn(state) {
        if (state.currentUser && Object.keys(state.currentUser).length > 0) {
            return state.currentUser
        }
        let user4Encode = window.localStorage.getItem(Vue.prototype.CURRENTUSER)
        if (!user4Encode || user4Encode == 'null') {
            user4Encode = Cookie.getCookie(Vue.prototype.CURRENTUSER);
        }
        if(user4Encode && window.decodeURIComponent(user4Encode).userId){
            Vue.prototype.userId = window.decodeURIComponent(user4Encode).userId;
            return user4Encode ? window.decodeURIComponent(user4Encode) : null;
        }
        if(user4Encode && window.decodeURIComponent(user4Encode) && JSON.parse(window.decodeURIComponent(user4Encode)) && JSON.parse(window.decodeURIComponent(user4Encode)).userId){
            Vue.prototype.userId = JSON.parse(window.decodeURIComponent(user4Encode)).userId;
        }
        return user4Encode ? JSON.parse(window.decodeURIComponent(user4Encode)) : null;
    },
    currentThirdFn(state) {
        if (state.currentThird && Object.keys(state.currentThird).length > 0 && state.currentThird.thirdId) {
            return state.currentThird
        }
        let third4Encode = window.localStorage.getItem(Vue.prototype.CURRENTTHIRD)
        if (!third4Encode || third4Encode == 'null') {
            third4Encode = Cookie.getCookie(Vue.prototype.CURRENTTHIRD);
        }
        if(third4Encode && window.decodeURIComponent(third4Encode).thirdId){
            Vue.prototype.thirdId = window.decodeURIComponent(third4Encode).thirdId;
            return third4Encode ? window.decodeURIComponent(third4Encode) : null;
        }
        if(third4Encode && window.decodeURIComponent(third4Encode) && JSON.parse(window.decodeURIComponent(third4Encode)) && JSON.parse(window.decodeURIComponent(third4Encode)).thirdId){
            Vue.prototype.thirdId = JSON.parse(window.decodeURIComponent(third4Encode)).thirdId;
        }
        return third4Encode ? JSON.parse(window.decodeURIComponent(third4Encode)) : null;
    },
    currentStoreFn(state) {
        if (state.currentStore && Object.keys(state.currentStore).length > 0 && state.currentStore.storeId) {
            return state.currentStore
        }
        let store4Encode = window.sessionStorage.getItem(Vue.prototype.CURRENTSTORE)
        if (!store4Encode || store4Encode == 'null') {
            store4Encode = Cookie.getCookie(Vue.prototype.CURRENTSTORE);
        }
        if(store4Encode && window.decodeURIComponent(store4Encode).storeId){
            Vue.prototype.storeId = window.decodeURIComponent(store4Encode).storeId;
            return store4Encode ? window.decodeURIComponent(store4Encode) : null;
        }
        if(store4Encode && window.decodeURIComponent(store4Encode) && JSON.parse(window.decodeURIComponent(store4Encode)) && JSON.parse(window.decodeURIComponent(store4Encode)).storeId){
            Vue.prototype.storeId = JSON.parse(window.decodeURIComponent(store4Encode)).storeId;
        }
        return store4Encode ? JSON.parse(window.decodeURIComponent(store4Encode)) : null;
    },
    currentUserStoreDiscountFn(state){
        if (state.userStoreDiscount) {
            return state.userStoreDiscount
        }
        let store4Encode = window.sessionStorage.getItem('userStoreDiscount') ? JSON.parse(window.sessionStorage.getItem('userStoreDiscount')) : 0
        return store4Encode
    }
}